//
//  RegisterViewController.m
//  AppointmentForCar
//
//  Created by Herron on 16/10/5.
//  Copyright © 2016年 Herron. All rights reserved.
//

#import "RegisterViewController.h"
#import "UserInfoViewController.h"

@interface RegisterViewController ()

@property (weak, nonatomic) IBOutlet UITextField *phoneTextField;
@property (weak, nonatomic) IBOutlet UITextField *codeTextField;
@property (nonatomic, copy) NSString *code;

@end

@implementation RegisterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"验证手机";
    if (self.navigationController.viewControllers.count == 1) {
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(cancle)];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (IBAction)sendVerificationCodeClick:(UIButton *)sender {
    if (self.phoneTextField.text.length == 0) {
        [HUDManager showWarningWithText:@"请输入手机号"];
        return;
    }
    if ([self.phoneTextField.text validateMobile]) {
        [NetWork postNetWorkWithUrl:kURLGetVerifycode parame:@{@"phoneNumber":_phoneTextField.text} successBlock:^(NSDictionary *dic) {
            NSLog(@"dic = %@", dic);
            self.code = dic[@"data"][@"verifyCode"];
        } errorBlock:^(id error) {
        }];
        [sender timeCountDown];
    }
}

- (IBAction)nextClick:(id)sender {
    if ([self.code isEqualToString:self.codeTextField.text]) {
        UserInfoViewController *vc = [[UserInfoViewController alloc] init];
        vc.invitationCode = self.invitationCode;
        vc.phone = self.phoneTextField.text;
        vc.code = self.code;
        [self.navigationController pushViewController:vc animated:YES];
    } else {
        [HUDManager showWarningWithText:@"验证码输入错误"];
    }
}

- (void)cancle {
    [self dismissViewControllerAnimated:YES completion:nil];
}

@end
